class QueryEntity {
    constructor({
                    ip = '',
                    firstTime = '',
                    lastTime = '',
                    timeArray = '',
                    startTime = '',
                    endTime = '',
                    houseId = '',
                } = {}) {
        this.ip = ip;
        this.firstTime = firstTime;
        this.lastTime = lastTime;
        this.timeArray = timeArray;
        this.startTime = startTime;
        this.endTime = endTime;
        this.houseId = houseId;
    }
}

const app = new BasicTableVue({
    data() {
        return {
            api: slogHotUrlApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({prop: 'id', title: 'ID'}),
                new TableColumn({prop: 'houseName', title: '所在机房'}),
                new TableColumn({prop: 'ip', title: '应用IP'}),
                new TableColumn({prop: 'visitsCount', title: '访问量'}),
                new TableColumn({prop: 'url', title: 'URL', customComponent: true}),
                new TableColumn({prop: 'firstTime', title: '首次采集时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'lastTime', title: '最后活跃时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'contentType', title: '访问内容类型'}),
                new TableColumn({prop: 'applicationProtocol', title: '应用协议类型', formatter: this.protocolFormat}),
                new TableColumn({prop: 'block', title: '阻断状态', formatter: this.blockFormat}),
            ],
            houses: [],
            blockMap: new Map()
                .set(0, '未阻断')
                .set(1, '阻断'),
            protocolMap: new Map()
                .set(1001, "SSL")
                .set(1002, "TLS")
                .set(1999, "其他")
                .set(2001, "FTP")
                .set(2002, "TFTP")
                .set(2003, "SFTP")
                .set(2004, "NNTP")
                .set(2005, "HTTP")
                .set(2006, "HTTPS")
                .set(2007, "WAP")
                .set(2008, "Gopher")
                .set(2009, "RPC")
                .set(2999, "其他")
                .set(3001, "SOCKS")
                .set(3999, "其他")
                .set(4001, "SIP")
                .set(4002, "SDP")
                .set(4003, "H.323")
                .set(4004, "MEGACO/H.248")
                .set(4005, "RTP")
                .set(4006, "RTCP")
                .set(4007, "RTSP")
                .set(4008, "RTMP")
                .set(4009, "HTTP FLV")
                .set(4010, "HLS")
                .set(4011, "HDS")
                .set(4012, "DASH")
                .set(4999, "其他")
                .set(5001, "LDAP")
                .set(5002, "SOAP")
                .set(5999, "其他")
                .set(6001, "XMPP")
                .set(6002, "IMPP")
                .set(6003, "PRIM")
                .set(6004, "IRC")
                .set(6999, "其他")
                .set(7001, "DNS")
                .set(7002, "mDNS")
                .set(7003, "NETBIOS")
                .set(7999, "其他")
                .set(8001, "RADIUS")
                .set(8999, "其他")
                .set(9001, "NTP")
                .set(9002, "SNTP")
                .set(9999, "其他")
                .set(10001, "SNMP")
                .set(10002, "CMIP")
                .set(10003, "DHCP")
                .set(10004, "NETCONF")
                .set(10005, "RMON")
                .set(10006, "SSDP")
                .set(10999, "其他")
                .set(11001, "SMTP")
                .set(11002, "POP3")
                .set(11003, "IMAP")
                .set(11004, "SMTPS")
                .set(11005, "POP3S")
                .set(11999, "其他")
                .set(12001, "Telnet")
                .set(12002, "Rlogin")
                .set(12003, "SSH")
                .set(12004, "VNC")
                .set(12005, "RFB")
                .set(12006, "RDP")
                .set(12007, "STUN")
                .set(12999, "其他")
                .set(13001, "CODESYS")
                .set(13002, "GE-SRTP")
                .set(13003, "SIEMENS-S7")
                .set(13004, "OMRON")
                .set(13005, "MODBUS")
                .set(13006, "FOX")
                .set(13007, "ETHERNET/IP")
                .set(13008, "DNP")
                .set(13009, "BACNET")
                .set(13010, "MELSEC-Q")
                .set(13011, "HART-IP")
                .set(13012, "PCWORX")
                .set(13013, "PROCONOS")
                .set(13014, "REDLION")
                .set(13015, "IEC 60870-5-104")
                .set(13016, "MOXA-NPORT")
                .set(13017, "CSP")
                .set(13018, "DDP")
                .set(13019, "HOLLYSYS-LK")
                .set(13020, "HOLLYSYS-MACS")
                .set(13021, "LANTRONIX")
                .set(13022, "WDBRPC")
                .set(13023, "DAHUA-DVR")
                .set(13024, "MMS")
                .set(13025, "ONVIF")
                .set(13999, "其他")
                .set(900, "其他"),
        }
    },
    methods: {
        createForm() {
            return new QueryEntity();
        },
        init() {
            this.initHouses();
        },
        initHouses: async function () {
            this.houses = await baseHouseInfoApi.selectList()
        },
        blockFormat(row, column, value, index) {
            return this.blockMap.get(parseInt(value));
        },
        protocolFormat(row, column, value, index) {
            return this.protocolMap.get(parseInt(value));
        },
        urlSubString(url) {
            if (url.length > 30) {
                return url.substring(0, 30) + '...';
            }
            return url;

        }
    },
    watch: {
        'form.timeArray': function (newVal, oldVal) {
            if (newVal) {
                this.form.startTime = newVal[0];
                this.form.endTime = newVal[1];
            } else {
                this.form.startTime = '';
                this.form.endTime = '';
            }

        },
    },
})
